//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "CommodityCurve.h"
using namespace Cephei::QL::Experimental::Commodities;
#include <gen/QL/Experimental/Commodities/CommodityType.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Experimental/Commodities/UnitOfMeasure.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/TermStructure.h>
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter) : CTermStructure(CCommodityCurve::typeid)
{
    CCommodityType^ _CcommodityType;
    CCurrency^ _Ccurrency;
    CUnitOfMeasure^ _CunitOfMeasure;
    CCalendar^ _Ccalendar;
    CDayCounter^ _CdayCounter;
    try
    {
#ifdef HANDLE
        _phCommodityCurve = NULL;
#endif
        std::string _name = (std::string)ValueHelper::Convert (name); //d
        _CcommodityType = safe_cast<CCommodityType^> (commodityType);
        _CcommodityType->Lock();
        QuantLib::CommodityType& _commodityType = static_cast<QuantLib::CommodityType&> (_CcommodityType->GetReference ()); 
        _Ccurrency = safe_cast<CCurrency^> (currency);
        _Ccurrency->Lock();
        QuantLib::Currency& _currency = static_cast<QuantLib::Currency&> (_Ccurrency->GetReference ()); 
        _CunitOfMeasure = safe_cast<CUnitOfMeasure^> (unitOfMeasure);
        _CunitOfMeasure->Lock();
        QuantLib::UnitOfMeasure& _unitOfMeasure = static_cast<QuantLib::UnitOfMeasure&> (_CunitOfMeasure->GetReference ()); 
        _Ccalendar = safe_cast<CCalendar^> (calendar);
        _Ccalendar->Lock();
        QuantLib::Calendar& _calendar = static_cast<QuantLib::Calendar&> (_Ccalendar->GetReference ()); 
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dayCounter))
        {
            _CdayCounter = safe_cast<CDayCounter^> (dayCounter->Value);
            _CdayCounter->Lock();
        }
        QuantLib::DayCounter& _dayCounter = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dayCounter) ? static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()) : QuantLib::Actual365Fixed()); //1
        _ppCommodityCurve = new boost::shared_ptr<QuantLib::CommodityCurve> (new QuantLib::CommodityCurve ( _name,  _commodityType,  _currency,  _unitOfMeasure,  _calendar,  _dayCounter ));
        SetTermStructure (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CcommodityType != nullptr) _CcommodityType->Unlock();
        if (_Ccurrency != nullptr) _Ccurrency->Unlock();
        if (_CunitOfMeasure != nullptr) _CunitOfMeasure->Unlock();
        if (_Ccalendar != nullptr) _Ccalendar->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Cephei::Core::IVector<DateTime>^ dates, Cephei::Core::IVector<Double>^ prices, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter) : CTermStructure(CCommodityCurve::typeid)
{
    CCommodityType^ _CcommodityType;
    CCurrency^ _Ccurrency;
    CUnitOfMeasure^ _CunitOfMeasure;
    CCalendar^ _Ccalendar;
    CDayCounter^ _CdayCounter;
    try
    {
#ifdef HANDLE
        _phCommodityCurve = NULL;
#endif
        std::string _name = (std::string)ValueHelper::Convert (name); //d
        _CcommodityType = safe_cast<CCommodityType^> (commodityType);
        _CcommodityType->Lock();
        QuantLib::CommodityType& _commodityType = static_cast<QuantLib::CommodityType&> (_CcommodityType->GetReference ()); 
        _Ccurrency = safe_cast<CCurrency^> (currency);
        _Ccurrency->Lock();
        QuantLib::Currency& _currency = static_cast<QuantLib::Currency&> (_Ccurrency->GetReference ()); 
        _CunitOfMeasure = safe_cast<CUnitOfMeasure^> (unitOfMeasure);
        _CunitOfMeasure->Lock();
        QuantLib::UnitOfMeasure& _unitOfMeasure = static_cast<QuantLib::UnitOfMeasure&> (_CunitOfMeasure->GetReference ()); 
        _Ccalendar = safe_cast<CCalendar^> (calendar);
        _Ccalendar->Lock();
        QuantLib::Calendar& _calendar = static_cast<QuantLib::Calendar&> (_Ccalendar->GetReference ()); 
        dates->Lock();
        INativeVector<DateTime>^ _NCIdates = dates->getFeature (NativeFeature::Value);
        CDateTimeVector^ _NCdates = safe_cast<CDateTimeVector^>(_NCIdates);
        std::vector<QuantLib::Date>& _dates = static_cast<std::vector<QuantLib::Date>&> (_NCdates->GetReference ());
        prices->Lock();
        INativeVector<Double>^ _NCIprices = prices->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCprices = safe_cast<CDoubleVector^>(_NCIprices);
        std::vector<QuantLib::Real>& _prices = static_cast<std::vector<QuantLib::Real>&> (_NCprices->GetReference ());
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dayCounter))
        {
            _CdayCounter = safe_cast<CDayCounter^> (dayCounter->Value);
            _CdayCounter->Lock();
        }
        QuantLib::DayCounter& _dayCounter = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dayCounter) ? static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()) : QuantLib::Actual365Fixed()); //1
        _ppCommodityCurve = new boost::shared_ptr<QuantLib::CommodityCurve> (new QuantLib::CommodityCurve ( _name,  _commodityType,  _currency,  _unitOfMeasure,  _calendar,  _dates,  _prices,  _dayCounter ));
        SetTermStructure (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CcommodityType != nullptr) _CcommodityType->Unlock();
        if (_Ccurrency != nullptr) _Ccurrency->Unlock();
        if (_CunitOfMeasure != nullptr) _CunitOfMeasure->Unlock();
        if (_Ccalendar != nullptr) _Ccalendar->Unlock();
        if (dates != nullptr) dates->Unlock();    //not optional
        if (prices != nullptr) prices->Unlock();    //not optional
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (boost::shared_ptr<QuantLib::CommodityCurve>& childNative, Object^ owner) : CTermStructure(CCommodityCurve::typeid)
{
#ifdef HANDLE
	_phCommodityCurve = NULL;
#endif
	_ppCommodityCurve = &childNative;
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
}
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (QuantLib::CommodityCurve& childNative, Object^ owner) : CTermStructure(CCommodityCurve::typeid)
{
#ifdef HANDLE
	_phCommodityCurve = NULL;
#endif
	_ppCommodityCurve = new boost::shared_ptr<QuantLib::CommodityCurve> (&childNative);
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
    _CommodityCurveOwner = owner;
    _TermStructureOwner = owner;
}

Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (CCommodityCurve^ copy) : CTermStructure(CCommodityCurve::typeid)
{
#ifdef HANDLE
	_phCommodityCurve = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCommodityCurve = new boost::shared_ptr<QuantLib::CommodityCurve> (copy->GetShared());
        _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
    }
}
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (PLATFORM::Type^ t) : CTermStructure(CCommodityCurve::typeid)
{
#ifdef HANDLE
	_phCommodityCurve = NULL;
#endif
	if (!t->IsSubclassOf(CCommodityCurve::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (QuantLib::Handle<QuantLib::CommodityCurve>& childNative, Object^ owner)  : CTermStructure(CCommodityCurve::typeid)
{
	_phCommodityCurve = &childNative;
	_ppCommodityCurve = &static_cast<boost::shared_ptr<QuantLib::CommodityCurve>>(childNative.currentLink());
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
    _CommodityCurveOwner = owner;
}
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (QuantLib::Handle<QuantLib::CommodityCurve> childNative)  : CTermStructure(CCommodityCurve::typeid)
{
	_phCommodityCurve = &childNative;
	_ppCommodityCurve = &static_cast<boost::shared_ptr<QuantLib::CommodityCurve>>(childNative.currentLink());
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Commodities::CCommodityCurve::CCommodityCurve (QuantLib::CommodityCurve childNative)  : CTermStructure(CCommodityCurve::typeid)
{
#ifdef HANDLE
	_phCommodityCurve = NULL;
#endif
	_ppCommodityCurve = new boost::shared_ptr<QuantLib::CommodityCurve> (new QuantLib::CommodityCurve (childNative));
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
}
#endif

Cephei::QL::Experimental::Commodities::CCommodityCurve::~CCommodityCurve ()
{
    if (_ppCommodityCurve != NULL)
    {
	    delete _ppCommodityCurve;
        _ppCommodityCurve = NULL;
    }
}
Cephei::QL::Experimental::Commodities::CCommodityCurve::!CCommodityCurve ()
{
    if (_ppCommodityCurve != NULL)
    {
	    delete _ppCommodityCurve;
    }
}
QuantLib::CommodityCurve& Cephei::QL::Experimental::Commodities::CCommodityCurve::GetReference ()
{
    if (_ppCommodityCurve == NULL) throw REFNEW NativeNullException ();
	return **_ppCommodityCurve;
}
boost::shared_ptr<QuantLib::CommodityCurve>& Cephei::QL::Experimental::Commodities::CCommodityCurve::GetShared ()
{
    if (_ppCommodityCurve == NULL) throw REFNEW NativeNullException ();
	return *_ppCommodityCurve;
}
QuantLib::CommodityCurve* Cephei::QL::Experimental::Commodities::CCommodityCurve::GetPointer ()
{
    if (_ppCommodityCurve == NULL) throw REFNEW NativeNullException ();
	return &**_ppCommodityCurve;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CommodityCurve>& Cephei::QL::Experimental::Commodities::CCommodityCurve::GetHandle ()
{
	if (_phCommodityCurve == NULL)
	{
		_phCommodityCurve = new Handle<QuantLib::CommodityCurve> (*_ppCommodityCurve);
	}
	return *_phCommodityCurve;
}
#endif
bool Cephei::QL::Experimental::Commodities::CCommodityCurve::HasNative () 
{
	return (_ppCommodityCurve != NULL);
}

Cephei::QL::Experimental::Commodities::ICommodityCurve^ Cephei::QL::Experimental::Commodities::CCommodityCurve::BasisOfCurve::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::CommodityCurve>& _rv = (boost::shared_ptr<QuantLib::CommodityCurve>&)(*_ppCommodityCurve)->basisOfCurve ( );   
        Cephei::QL::Experimental::Commodities::CCommodityCurve^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CCommodityCurve (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Commodities::CCommodityCurve::BasisOfPrice (DateTime d)
{
    try
    {
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCommodityCurve)->basisOfPrice ( _d );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::ICommodityType^ Cephei::QL::Experimental::Commodities::CCommodityCurve::CommodityType::get ()
{
    try
    {
    	QuantLib::CommodityType& _rv = (QuantLib::CommodityType&)(*_ppCommodityCurve)->commodityType ( );   
        Cephei::QL::Experimental::Commodities::CCommodityType^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CCommodityType (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::ICurrency^ Cephei::QL::Experimental::Commodities::CCommodityCurve::Currency::get ()
{
    try
    {
    	QuantLib::Currency& _rv = (QuantLib::Currency&)(*_ppCommodityCurve)->currency ( );   
        Cephei::QL::CCurrency^ _nrv = REFNEW Cephei::QL::CCurrency (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<DateTime>^ Cephei::QL::Experimental::Commodities::CCommodityCurve::Dates::get ()
{
    try
    {
    	std::vector<QuantLib::Date>& _rv = (std::vector<QuantLib::Date>&)(*_ppCommodityCurve)->dates ( );   
        Cephei::Core::IVector<DateTime>^ _nrv = REFNEW CoVector<DateTime> (REFNEW CDateTimeVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Experimental::Commodities::CCommodityCurve::Empty::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppCommodityCurve)->empty ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Experimental::Commodities::CCommodityCurve::MaxDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppCommodityCurve)->maxDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Experimental::Commodities::CCommodityCurve::Name::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppCommodityCurve)->name ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Commodities::CCommodityCurve::Prices::get ()
{
    try
    {
    	std::vector<QuantLib::Real>& _rv = (std::vector<QuantLib::Real>&)(*_ppCommodityCurve)->prices ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::ICommodityCurve^ Cephei::QL::Experimental::Commodities::CCommodityCurve::SetBasisOfCurve (Cephei::QL::Experimental::Commodities::ICommodityCurve^ basisOfCurve)
{
    CCommodityCurve^ _CbasisOfCurve;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _CbasisOfCurve = safe_cast<CCommodityCurve^> (basisOfCurve);
        _CbasisOfCurve->Lock();
        boost::shared_ptr<QuantLib::CommodityCurve>& _basisOfCurve = static_cast<boost::shared_ptr<QuantLib::CommodityCurve>&> (_CbasisOfCurve->GetShared ()); 
    	(*_ppCommodityCurve)->setBasisOfCurve ( _basisOfCurve );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CbasisOfCurve != nullptr) _CbasisOfCurve->Unlock();
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Commodities::CCommodityCurve::Times::get ()
{
    try
    {
    	std::vector<QuantLib::Time>& _rv = (std::vector<QuantLib::Time>&)(*_ppCommodityCurve)->times ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ Cephei::QL::Experimental::Commodities::CCommodityCurve::UnitOfMeasure::get ()
{
    try
    {
    	QuantLib::UnitOfMeasure& _rv = (QuantLib::UnitOfMeasure&)(*_ppCommodityCurve)->unitOfMeasure ( );   
        Cephei::QL::Experimental::Commodities::CUnitOfMeasure^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CUnitOfMeasure (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Commodities::ICommodityCurve^ Cephei::QL::Experimental::Commodities::CCommodityCurve_Factory::Create (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter)
{
    return REFNEW CCommodityCurve ( name,  commodityType,  currency,  unitOfMeasure,  calendar,  dayCounter);
}
Cephei::QL::Experimental::Commodities::ICommodityCurve^ Cephei::QL::Experimental::Commodities::CCommodityCurve_Factory::Create (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Cephei::Core::IVector<DateTime>^ dates, Cephei::Core::IVector<Double>^ prices, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter)
{
    return REFNEW CCommodityCurve ( name,  commodityType,  currency,  unitOfMeasure,  calendar,  dates,  prices,  dayCounter);
}
